# coding=utf-8
import os


class BaseConfig(object):
    PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
    # SQLALCHEMY_DATABASE_URI = "mysql+pymysql://%s:%s@%s:%d/%s?charset=utf8&use_unicode=0" % (
    #     'root', '123456',
    #     '172.16.3.192', 3307,
    #     'beetle-plan'
    # )
    SQLALCHEMY_DATABASE_URI = "mysql+pymysql://%s:%s@%s:%d/%s?charset=utf8&use_unicode=0" % (
        'root', 'root',
        '192.168.56.111', 3307,
        'beetle-plan'
    )

    # 自动回收连接的秒数。这对 MySQL 是必须的，默认 情况下 MySQL 会自动移除闲置 8 小时或者以上的连接。 需要注意地是如果使用 MySQL 的话， Flask-SQLAlchemy 会自动地设置这个值为 2 小时。
    SQLALCHEMY_POOL_RECYCLE = 1200
    # 控制在连接池达到最大值后可以创建的连接数。当这些额外的 连接回收到连接池后将会被断开和抛弃。
    SQLALCHEMY_MAX_OVERFLOW = 10

    DEBUG = False

    ENABLED_MODULES = (
        'common',
        'zentao',
        'cache',
        'project',
        'projectPlan',
        'integration',
        'status',
        'operation',
        'thread',
        'notify',
        'api',
    )

    AUTHORIZATIONS = {
        'oauth2_password': {
            'type': 'oauth2',
            'flow': 'password',
            'scopes': {},
            'tokenUrl': '/auth/oauth2/token',
        },
    }

    JOBS = [
        {
            'id': 'createIntegrationJob',
            'func': 'app.modules.common.scheduler:createIntegration',
            'args': (),
            'trigger': 'cron',
            'hour': 0
        }
    ]

    SWAGGER_UI_JSONEDITOR = True
    SWAGGER_UI_OAUTH_CLIENT_ID = 'documentation'
    SWAGGER_UI_OAUTH_REALM = 'Authentication for beetle-plan documentation'
    SWAGGER_UI_OAUTH_APP_NAME = 'beetle-plan documentation'

    SQLALCHEMY_TRACK_MODIFICATIONS = True
    CSRF_ENABLED = True

    ROLE_ADMIN_ID = 1

    BEETLE_API_URL = 'http://192.168.56.2:8080/beetle'
    # BEETLE_API_URL = 'http://172.16.3.192:8081/beetle'
    # BEETLE_API_URL = 'http://172.16.3.166:8081/beetle'

    UCLOUD_MASTER_URL = 'http://192.168.56.113:5002/api/v1'
    # UCLOUD_MASTER_URL = 'http://172.16.3.192:5002/api/v1'

    SVN_URL = 'svn://192.168.56.111/WJ/winit'
    # SVN_URL = 'https://192.168.130.6:8443/svn/winit2.0'

    # INTEGRATION_AGENT_URL = 'http://172.16.3.207:5000/api/v1'

    BEETLE_BASE_PATH = "/usr/local/Beetle"

    SVN_TRUNK_NAME = {
        'ups2': 'ups2.0'
    }

    NOT_CHECK_DEPENDENCIE = {
        'oms2': {
            'spi': 'spi.version',
            'winit-core': 'winit.core.version',
            'winit-commons': 'winit.common.version'
        }
    }

    # BEETLE_AUTH_URL = 'http://172.16.3.192:5001/api/v1/login/info'
    BEETLE_AUTH_URL = 'http://192.168.56.113:5001/api/v1/login/info'

    NOTIFY_ASYNC_MODE = None

    ADFolder = {
        "erp": ["/mnt/build/tms", "/mnt/winitRelease/tms"],
        "owms": ["/mnt/build/owms", "/mnt/winitRelease/owms"],
        "owms_usla": ["/mnt/build/owms", "/mnt/winitRelease/owms"],
        "owms_bemo": ["/mnt/build/owms", "/mnt/winitRelease/owms"],
        "nothing": [""]
    }

    DRAW_SQL_STATUS_FILE = "/usr/local/Beetle/sql/status/"

    CACHE_CONFIG = {
        'CACHE_TYPE': 'redis',
        'CACHE_REDIS_HOST': '192.168.56.111',
        'CACHE_REDIS_PORT': 6379,
        'CACHE_KEY_PREFIX': 'beetle-plan_',
        'CACHE_DEFAULT_TIMEOUT': 60 * 30
    }

    GET_TRUNK_LIST = False
    OPERATE_ZENTAO = False


class DevelopmentConfig(BaseConfig):
    DEBUG = False


class TestingConfig(BaseConfig):
    DEBUG = True


class ProductionConfig(BaseConfig):
    pass


class LocalConfig(BaseConfig):
    DEBUG = True


class ZenTaoConfig(object):
    IS_USE_ZENTAO = False

    ZENTAO_GETSESSION_URL = '/index.php?m=api&f=getSessionID&t=json'
    ZENTAO_USER_LOGIN_URL = '/index.php?m=user&f=login&t=json'

    ZENTAO_COMPANY_VIEW_URL = '/index.php?m=company&f=view&t=json'
    ZENTAO_COMPANY_BROWSE_URL = '/index.php?m=company&f=browse&t=json&param=0&type=bydept&orderBy=id&recTotal=9999' \
                                '&recPerPage=9999&pageID=1 '

    ZENTAO_PROJECT_LIST_URL = '/index.php?m=project&f=ajaxGetDropMenu&t=json&objectID=0&module=project&method=task' \
                              '&extra=all '
    ZENTAO_PROJECT_TEAM_URL = '/index.php?m=project&f=team&t=json'
    ZENTAO_PROJECT_VIEW_URL = '/index.php?m=project&f=view&t=json'

    ZENTAO_PROJECT_ADD_BUILD_URL = '/index.php?m=build&f=create&t=json'
    ZENTAO_PROJECT_PRODUCT_LIST_URL = '/index.php?m=project&f=manageproducts&t=json'

    ZENTAO_PRODUCT_LIST_URL = '/index.php?m=product&f=index&t=json&locate=no&productID=0&orderBy=order_desc&recPerPage=9999&pageID=1'

    ZENTAO_CREATE_TEST_TASK_URL = '/index.php?m=testtask&f=create&t=json&product=0'

    ZENTAO_CREATE_PLAN_URL = '/index.php?m=project&f=create&t=json'
    ZENTAO_UPDATE_PLAN_MEMBERS_URL = '/index.php?m=project&f=managemembers&t=json'
    ZENTAO_DELETE_PLAN_MEMBERS_URL = '/index.php?m=project&f=unlinkMember'
    ZENTAO_UPDATE_PLAN_URL = '/index.php?m=project&f=edit&t=json'
